<?php

class MessageController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $view = $this->view;
        
        $articleId = $this->_request->getParam('articleid', 0);
        $post = new Business_Post();
        //获取简短联系方式
        $shortContact = $post->getByCateId(1);
        if (isset($shortContact[0]) && isset($shortContact[0]['content'])) {
        	$view->shortContact = $shortContact[0]['content'];
        } else {
        	$view->shortContact = '';
        }
        
        //获取脚注信息
        $footInfo = $post->getByCateId(3);
        if (isset($footInfo[0]) && isset($footInfo[0]['content'])) {
        	$view->footInfo = $footInfo[0]['content'];
        } else {
        	$view->footInfo = '';
        }
        
        //获取公司简介文章
        $articles = $post->getByCateId(5);
        $view->articles = $articles;
        
        
        
        $message = new Business_Message();
        //当前页码
        $view->page = $page = $this->_request->getParam('page', 1);
        //记录总数
        $amount = $message->getAmount();
        $view->amount = $amount;
        //每页显示
        $rowCount = Zend_Registry::get('data')->message->numPerPage;
        $view->rowCount = $rowCount;
        //总页数
        $view->total = $total = ceil($amount / $rowCount);
        //页码超过范围处理
        if ($page < 1) {
        	$view->page = $page = 1;
        }
        if ($page > $total) {
        	$view->page = $page = $total;
        }
        
        $view->list = $messageList = $message->get($page, $rowCount);
        
    }
    
    public function saveAction()
    {
    	$title = $this->_request->getParam('title', '');
    	$name = $this->_request->getParam('name', '');
    	$email = $this->_request->getParam('email', '');
    	$qq = $this->_request->getParam('qq', 0);
    	$homepage = $this->_request->getParam('homepage', '');
    	$head = $this->_request->getParam('head', '/public/images/headpics/m01.gif');
    	$content = $this->_request->getParam('content', '');
    	$isshow = $this->_request->getParam('isshow', 1);
    
    	$data = array(
    		'title' => $title,
    		'content' => $content,
    		'homepage' => $homepage,
    	    'username' => $name,
    	    'email' => $email,
    	    'qq' => $qq,
    	    'head' => $head,
    	    'isshow' => $isshow
    	);
    	$feedback = new Business_Message();
    	$rowNum = $feedback->insert($data);
    
    	if ($rowNum) {
    		$result = array(
    				'errorcode' => 0,
    				'errormsg' => '提交成功！'
    		);
    	} else {
    		$result = array(
    				'errorcode' => -1,
    				'errormsg' => '提交失败！'
    		);
    	}
    	$this->_helper->getHelper('Json')->sendJson($result);
    }
}

